
//2730.找到最长的半重复子字符串
class Solution {
public:
    int longestSemiRepetitiveSubstring(string s) {
        //通过滑动窗口来实现
        int n=s.size();
        int left=0,count=0;   //count记录窗口中相邻字符相等的个数
        int ret=1;  
        for(int right=1;right<n;right++)
        {
            if(s[right-1]==s[right]) count++;  //相邻字符相等

            while(count>1)   //出窗口   
            {
                if(s[left]==s[left+1]) count--;
                left++;  
            }
            ret=max(ret,right-left+1);   //更新答案
        }
        return ret;
    }
};